package com.facebook.app.client.uiElements;

import java.util.List;

import com.facebook.app.shared.clustering.Clusterable;
import com.facebook.app.shared.facebookData.FacebookFriend;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.CompositeCell;
import com.google.gwt.cell.client.HasCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

public class ClusterableCompositeCell extends CompositeCell<Clusterable> {

	public ClusterableCompositeCell(List<HasCell<Clusterable, ?>> hasCells) {
		super(hasCells);
	}

	@Override
	public void render(Context context, Clusterable value, SafeHtmlBuilder sb) {
		if (value != null && value instanceof FacebookFriend) {
			sb.appendHtmlConstant("<table><tbody><tr>");
			super.render(context, value, sb);
			sb.appendHtmlConstant("</tr></tbody></table>");
		}
	}

	@Override
	protected <T> void render(Context context, Clusterable value,
			SafeHtmlBuilder sb, HasCell<Clusterable, T> hasCell) {
		if (value != null && value instanceof FacebookFriend) {
			Cell<T> cell = hasCell.getCell();
			sb.appendHtmlConstant("<td>");
			cell.render(context, hasCell.getValue(value), sb);
			sb.appendHtmlConstant("</td>");
			sb.appendHtmlConstant("<td></td>");
		}
	}
}
